import { App } from 'vue'
// import chooseArea from './chooseArea';
// import chooseAreaPcas from './chooseArea/indexPcas';
// import chooseIcon from './chooseIcon';
// import navSide from './container';
// import navHeader from './container/indexHeader';
// import trend from './trend';
// import notification from './notification'
// import list from './list';
// import menu from './menu';
// import progress from './progress';
// import chooseCity from './chooseCity';

// const components = [
//   chooseArea, chooseAreaPcas,
//   chooseIcon,
//   navSide, navHeader,
//   trend, // 趋势剪头
//   notification, list,
//   menu, progress, chooseCity
// ]

import { defineAsyncComponent } from 'vue';
import * as Icons from '@element-plus/icons-vue'
import 'element-plus/dist/index.css'
// 取组件name defineComponent {name:xxx} 才有效
// const componentsName = import.meta.globEager('./*/index*.vue');
const components = import.meta.glob('./**/index*.vue');

export default {
  install(app: App) {
    // ---------------- element icons -------------    
    // 全局注册图标  el-icon-图标名
    for (let i in Icons) { // 转换图标名: Edit -> el-icon-edit
      app.component(`el-icon-${i.replace(/(A-Z)g/, '-$1').toLocaleLowerCase()
        }`, (Icons as any)[i])
    }
    // 插件自动加载
    for (const [key, value] of Object.entries(components)) {
      // 注册组件名字: 引用文件组件文件夹名字
      // chooseArea/indexPcas.vue => chooseAreaPcas
      let name: string = key.replace('/index', '').replace('.vue', '')
      // container/navSide => nav-side
      name = name.slice(name.lastIndexOf('/') + 1)
      name = name.replace(/([A-Z])/g, '-$1').toLowerCase()

      app.component('hf-' + name, defineAsyncComponent(value));
    }
  }
}
